package tdhclient

import org.apache.hadoop.security.UserGroupInformation
import org.apache.spark.sql.SparkSession
import org.apache.spark.{SparkConf, SparkContext}

object test {
  System.setProperty("java.security.krb5.conf","D:\\obj\\tdhclient\\conf\\krb5.conf" )
  def main(args: Array[String]): Unit = {
    val conf: SparkConf = new SparkConf().setAppName("SparkRreadHdfs").setMaster("local[*]")
    val sparkSession: SparkSession = SparkSession.builder().config(conf).getOrCreate()
    val sc: SparkContext = sparkSession.sparkContext
    sc.hadoopConfiguration.set("hadoop.security.authentication","kerberos")
    sc.hadoopConfiguration.addResource("core-site.xml")
    sc.hadoopConfiguration.addResource("hdfs-site.xml")
    sc.hadoopConfiguration.addResource("yarn-site.xml")
    //用户登录
    UserGroupInformation.setConfiguration(sc.hadoopConfiguration)
    UserGroupInformation.loginUserFromKeytab("bdps","D:\\obj\\tdhclient\\conf\\keytab")
    //读取Thread.currentThread.getContextClassLoader.getResource("D:\\obj\\tdhclient\\conf\\keytab").getPath
//    val lines = sc.textFile("hdfs://nameservice1/des/aaa.json")
//    lines.foreach(println)
  val lines = sparkSession.read.textFile("hdfs://nameservice1/des/aaa.json")
    lines.show()
  }
}
